﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using lgweb.common;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;
using KMFrame.Permission.Util;
using LGCourt.Logic.Common;

namespace lgweb.inside.department
{
    public partial class detail : NeedValidatePage
    {
        private int _aid = 1;
        public string _cate = "0";
        public string _DeptID = "0";
        public string _ClassID = "0";
        public string _picUrl = "";
        public string _DetpName = "";
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "/lgmanage/Systems/upload/" : _picUrl;
                GetParam();
               // GetUserInfo();
                GetDeptInfo();
                GetInfo();
                //GetDBImgList();
            }
        }

        private void GetParam()
        {           
            this._aid = string.IsNullOrEmpty(Request.QueryString["id"]) ? 1 : Convert.ToInt32(Request.QueryString["id"]);
            this._DeptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" :Request.QueryString["deptid"].ToString();
            this._ClassID = string.IsNullOrEmpty(Request.QueryString["classid"]) ? "0" : Request.QueryString["classid"].ToString();
            this._cate = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
        }

        //获取个人信息
        private void GetUserInfo()
        {
            OA bll = new OA();
            vOAUser result = (vOAUser)bll.GetUserInfo(SessionBox.GetUserSession().UserID);

          
        }

        //获取部门信息
        private void GetDeptInfo()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();
            //取部门
            param.Name = "部门";
            param.ClassID = int.Parse(_DeptID);
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
            }
            _DetpName = deptInfo.Source;        
            this.spDeptMent.InnerHtml = _DetpName;
            this.spDeptMent.HRef = "/inside/department/index.aspx?deptid=" + this._DeptID;

            //取栏目
            param.Name = "部门栏目";
            param.ClassID = int.Parse(_ClassID);
            V_DICT_SOURCE classInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (classInfo == null)
            {
                classInfo = new V_DICT_SOURCE();
            }

            DeptCondition deptParam = new DeptCondition();
            deptParam.ClassID = classInfo.ID.GetValueOrDefault(0);
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            IF_DeptClass deptClass = colInfoBLL.GetDeptClassInfo(deptParam);
            this.spBaoCate.InnerHtml = deptClass == null ? classInfo.Source : deptClass.ClassName;
            this.spBaoCate.HRef = "/inside/department/list.aspx?classid=" + this._ClassID + "&deptid=" + this._DeptID;

            //部门信息
            deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            spInfoEditer.InnerText = deptIndex == null ? "" : deptIndex.Managers;
            //string deptName = "";
            //DepartmentHandler departmentHandler = new DepartmentHandler();
            //Department department = departmentHandler.GetDepartmentInfo(this._Code);
            //if (department != null)
            //{

            //    deptName = department.Name;
            //    this.topDepart.InnerHtml = department.Name;//部门名称
            //    //this.welcome.InnerHtml = "欢迎您登录" + department.Name + "信息平台";
            //    _DetpName = department.Name;
            //    this.spDeptMent.InnerHtml = deptName;
            //    this.spDeptMent.HRef = "/inside/department/index.aspx?Code=" + this._Code;
            //}

            //BBS bbsBLL = new BBS();
            //InfoCondition infoParam = new InfoCondition();
            //infoParam.PageSize = 1;
            //infoParam.InfoTag = "顶部图片";
            //infoParam.UpInfoTag = deptName;
            //IEnumerable<vPortalArticleTitleEx> DTList = bbsBLL.GetNewsInfoTop(infoParam);
            //if (DTList != null)
            //{
            //    this.rptImgList.DataSource = DTList;
            //    this.rptImgList.DataBind();
            //}
        }

        private void GetInfo()
        {
            //BBS bll = new BBS();
            //InfoCondition param = new InfoCondition();
            //param.aid = this._aid;
            //vPortalArticleTitleEx result = (vPortalArticleTitleEx)bll.GetInfo(param);
            ColInfo bll = new ColInfo();
            DeptCondition param = new DeptCondition();
            param.id =_aid ;
            LGFY_Platform_Bmxx result = (LGFY_Platform_Bmxx)bll.GetDeptColInfo(param);

            if (result != null)
            {               
                this.author.InnerHtml = result.Publishers;
                this.title.InnerHtml = result.Title;
                this.InfoFrom.InnerHtml = result.Comefrom;
                this.content.InnerHtml = result.Text;
                this.viewCount.InnerHtml = result.Hit.ToString();
                this.dtime.InnerHtml = result.PubDate.GetValueOrDefault().ToString("yyyy-MM-dd HH:mm");
            }
        }

    }
}